package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import org.springframework.beans.factory.annotation.Autowired;

import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalErrorConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.util.StrTools;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInstFunc;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

/**
 *
 */
public class SMSAmountAttrHandler<I extends KiteInst, D extends AttrData>
    extends AbstractAttrHandler<KiteInst, AttrData> {
    @Autowired
    IQuerySceneInstService querySceneInstService;

    @Override
    public void before(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        
        String sceneValue = null;
        KiteProdInstFunc prodInstFunc = ((KiteProdInstFunc) inst);
        KiteProdInst accProdInst = this.querySceneInstService.getProdInst(data.getCustId(), prodInstFunc.getAccProdInstId());
        if (!KiteObjectUtils.isEmpty(accProdInst)) {
            // 业务场景属性值
            sceneValue = accProdInst.getAttrValue("200001679");
        }
        
        if (KiteStringUtils.equals(sceneValue, LocalKeyConsts.SCENE_B2B) && StrTools.isNotEmpty(value) && value.split(",").length > 20) {
            LocalErrorConsts.BSS_KITE_ATTR_43084.throwOut(20);
        }
        else if (KiteStringUtils.equals(sceneValue, LocalKeyConsts.SCENE_B2B2C) && StrTools.isNotEmpty(value) && value.split(",").length > 100) {
            LocalErrorConsts.BSS_KITE_ATTR_43084.throwOut(100);
        }
        
    }
}
